

<!DOCTYPE html>
<!--[if IE 8]><html class="no-js lt-ie9" lang="en" > <![endif]-->
<!--[if gt IE 8]><!--> <html class="no-js" lang="en" > <!--<![endif]-->
<head>
  <meta charset="utf-8">
  
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  
  <title>Models &mdash; Twitter Geolocation Predictor 0.1 documentation</title>
  

  
  
  
  

  

  
  
    

  

  
  
    <link rel="stylesheet" href="../_static/css/theme.css" type="text/css" />
  

  

  
        <link rel="index" title="Index"
              href="../genindex.html"/>
        <link rel="search" title="Search" href="../search.html"/>
    <link rel="top" title="Twitter Geolocation Predictor 0.1 documentation" href="../index.html"/>
        <link rel="prev" title="Data" href="twgeo.data.html"/>
    <link href="../_static/mystyles.css" rel="stylesheet" type="text/css">


  
  <script src="../_static/js/modernizr.min.js"></script>

</head>

<body class="wy-body-for-nav" role="document">

   
  <div class="wy-grid-for-nav">

    
    <nav data-toggle="wy-nav-shift" class="wy-nav-side">
      <div class="wy-side-scroll">
        <div class="wy-side-nav-search">
          

          
            <a href="../index.html" class="icon icon-home"> Twitter Geolocation Predictor
          

          
          </a>

          
            
            
              <div class="version">
                0.1
              </div>
            
          

          
<div role="search">
  <form id="rtd-search-form" class="wy-form" action="../search.html" method="get">
    <input type="text" name="q" placeholder="Search docs" />
    <input type="hidden" name="check_keywords" value="yes" />
    <input type="hidden" name="area" value="default" />
  </form>
</div>

          
        </div>

        <div class="wy-menu wy-menu-vertical" data-spy="affix" role="navigation" aria-label="main navigation">
          
            
            
              
            
            
              <p class="caption"><span class="caption-text">API</span></p>
<ul class="current">
<li class="toctree-l1"><a class="reference internal" href="twgeo.data.html">Data</a></li>
<li class="toctree-l1 current"><a class="current reference internal" href="#">Models</a><ul>
<li class="toctree-l2"><a class="reference internal" href="#module-twgeo.models.geomodel">twgeo.models.geomodel</a></li>
<li class="toctree-l2"><a class="reference internal" href="#module-twgeo.models">Module contents</a></li>
</ul>
</li>
</ul>

            
          
        </div>
      </div>
    </nav>

    <section data-toggle="wy-nav-shift" class="wy-nav-content-wrap">

      
      <nav class="wy-nav-top" role="navigation" aria-label="top navigation">
        
          <i data-toggle="wy-nav-top" class="fa fa-bars"></i>
          <a href="../index.html">Twitter Geolocation Predictor</a>
        
      </nav>


      
      <div class="wy-nav-content">
        <div class="rst-content">
          















<div role="navigation" aria-label="breadcrumbs navigation">

  <ul class="wy-breadcrumbs">
    
      <li><a href="../index.html">Docs</a> &raquo;</li>
        
      <li>Models</li>
    
    
      <li class="wy-breadcrumbs-aside">
        
            
            <a href="../_sources/source/twgeo.models.rst.txt" rel="nofollow"> View page source</a>
          
        
      </li>
    
  </ul>

  
  <hr/>
</div>
          <div role="main" class="document" itemscope="itemscope" itemtype="http://schema.org/Article">
           <div itemprop="articleBody">
            
  <div class="section" id="models">
<h1>Models<a class="headerlink" href="#models" title="Permalink to this headline">¶</a></h1>
<div class="section" id="module-twgeo.models.geomodel">
<span id="twgeo-models-geomodel"></span><h2>twgeo.models.geomodel<a class="headerlink" href="#module-twgeo.models.geomodel" title="Permalink to this headline">¶</a></h2>
<dl class="class">
<dt id="twgeo.models.geomodel.Model">
<em class="property">class </em><code class="descclassname">twgeo.models.geomodel.</code><code class="descname">Model</code><span class="sig-paren">(</span><em>use_tensorboard=True</em>, <em>batch_size=64</em><span class="sig-paren">)</span><a class="headerlink" href="#twgeo.models.geomodel.Model" title="Permalink to this definition">¶</a></dt>
<dd><p>Bases: <a class="reference external" href="https://docs.python.org/2/library/functions.html#object" title="(in Python v2.7)"><code class="xref py py-class docutils literal"><span class="pre">object</span></code></a></p>
<p>Geolocation prediction model. Consists of 4 layers ( Embedding, LSTM, LSTM and Dense).</p>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><ul class="first last simple">
<li><strong>use_tensorboard</strong> – Track training progress using Tensorboard. Default: true.</li>
<li><strong>batch_size</strong> – Default: 64</li>
</ul>
</td>
</tr>
</tbody>
</table>
<dl class="method">
<dt id="twgeo.models.geomodel.Model.build_model">
<code class="descname">build_model</code><span class="sig-paren">(</span><em>num_outputs</em>, <em>time_steps=500</em>, <em>vocab_size=20000</em>, <em>hidden_layer_size=128</em><span class="sig-paren">)</span><a class="headerlink" href="#twgeo.models.geomodel.Model.build_model" title="Permalink to this definition">¶</a></dt>
<dd><p>Build the model.</p>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><ul class="first simple">
<li><strong>num_outputs</strong> – Number of output classes. For example, in the case of Census regions num of classes is 4.</li>
<li><strong>time_steps</strong> – Default: 500</li>
<li><strong>vocab_size</strong> – Use the top N most frequent words. Default: 20,000</li>
<li><strong>hidden_layer_size</strong> – Number of neurons in the hidden layers. Default: 128</li>
</ul>
</td>
</tr>
<tr class="field-even field"><th class="field-name">Returns:</th><td class="field-body"><p class="first last"></p>
</td>
</tr>
</tbody>
</table>
</dd></dl>

<dl class="method">
<dt id="twgeo.models.geomodel.Model.evaluate">
<code class="descname">evaluate</code><span class="sig-paren">(</span><em>x_test</em>, <em>y_test</em><span class="sig-paren">)</span><a class="headerlink" href="#twgeo.models.geomodel.Model.evaluate" title="Permalink to this definition">¶</a></dt>
<dd><p>Get the loss, accuracy and top 5 accuracy of the model.</p>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><ul class="first simple">
<li><strong>x_test</strong> – Evaluation samples.</li>
<li><strong>y_test</strong> – Evaluation labels.</li>
</ul>
</td>
</tr>
<tr class="field-even field"><th class="field-name">Returns:</th><td class="field-body"><p class="first last">A dictionary of metric, value pairs.</p>
</td>
</tr>
</tbody>
</table>
</dd></dl>

<dl class="method">
<dt id="twgeo.models.geomodel.Model.load_saved_model">
<code class="descname">load_saved_model</code><span class="sig-paren">(</span><em>filename</em><span class="sig-paren">)</span><a class="headerlink" href="#twgeo.models.geomodel.Model.load_saved_model" title="Permalink to this definition">¶</a></dt>
<dd><p>Load a previously trained model from disk.</p>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><strong>filename</strong> – The H5 model.</td>
</tr>
<tr class="field-even field"><th class="field-name">Returns:</th><td class="field-body"></td>
</tr>
</tbody>
</table>
</dd></dl>

<dl class="method">
<dt id="twgeo.models.geomodel.Model.predict">
<code class="descname">predict</code><span class="sig-paren">(</span><em>x</em><span class="sig-paren">)</span><a class="headerlink" href="#twgeo.models.geomodel.Model.predict" title="Permalink to this definition">¶</a></dt>
<dd><p>Predict the location of the given samples.</p>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><strong>x</strong> – A vector of tweets. Each row corresponds to a single user.</td>
</tr>
<tr class="field-even field"><th class="field-name">Returns:</th><td class="field-body">The prediction results.</td>
</tr>
</tbody>
</table>
</dd></dl>

<dl class="method">
<dt id="twgeo.models.geomodel.Model.save_model">
<code class="descname">save_model</code><span class="sig-paren">(</span><em>filename</em><span class="sig-paren">)</span><a class="headerlink" href="#twgeo.models.geomodel.Model.save_model" title="Permalink to this definition">¶</a></dt>
<dd><p>Save the current model and trained weights for later use.</p>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><strong>filename</strong> – Prefix for the model filenames.</td>
</tr>
</tbody>
</table>
</dd></dl>

<dl class="method">
<dt id="twgeo.models.geomodel.Model.train">
<code class="descname">train</code><span class="sig-paren">(</span><em>x_train</em>, <em>y_train</em>, <em>x_dev</em>, <em>y_dev</em>, <em>epochs=7</em>, <em>reset_model=False</em><span class="sig-paren">)</span><a class="headerlink" href="#twgeo.models.geomodel.Model.train" title="Permalink to this definition">¶</a></dt>
<dd><p>Fit the model to the training data.</p>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><ul class="first simple">
<li><strong>x_train</strong> – Training samples.</li>
<li><strong>y_train</strong> – Training labels. Must be a vector of integer values.</li>
<li><strong>x_dev</strong> – Validation samples.</li>
<li><strong>y_dev</strong> – Validation labels. Must be a vector of integer values.</li>
<li><strong>epochs</strong> – Number of times to train on the whole data set. Default: 7</li>
<li><strong>reset_model</strong> – If this is set to True, it will discard any previously trained model and start from scratch.</li>
</ul>
</td>
</tr>
<tr class="field-even field"><th class="field-name">Returns:</th><td class="field-body"><p class="first"></p>
</td>
</tr>
<tr class="field-odd field"><th class="field-name">Raises:</th><td class="field-body"><p class="first last">ValueError: If the number of training samples and the number of labels do not match.</p>
</td>
</tr>
</tbody>
</table>
</dd></dl>

</dd></dl>

<dl class="function">
<dt id="twgeo.models.geomodel.top_5_acc">
<code class="descclassname">twgeo.models.geomodel.</code><code class="descname">top_5_acc</code><span class="sig-paren">(</span><em>y_true</em>, <em>y_pred</em><span class="sig-paren">)</span><a class="headerlink" href="#twgeo.models.geomodel.top_5_acc" title="Permalink to this definition">¶</a></dt>
<dd></dd></dl>

</div>
<div class="section" id="module-twgeo.models">
<span id="module-contents"></span><h2>Module contents<a class="headerlink" href="#module-twgeo.models" title="Permalink to this headline">¶</a></h2>
</div>
</div>


           </div>
           <div class="articleComments">
            
           </div>
          </div>
          <footer>
  
    <div class="rst-footer-buttons" role="navigation" aria-label="footer navigation">
      
      
        <a href="twgeo.data.html" class="btn btn-neutral" title="Data" accesskey="p" rel="prev"><span class="fa fa-arrow-circle-left"></span> Previous</a>
      
    </div>
  

  <hr/>

  <div role="contentinfo">
    <p>
        &copy; Copyright 2017, Javier Matias.

    </p>
  </div>
  Built with <a href="http://sphinx-doc.org/">Sphinx</a> using a <a href="https://github.com/snide/sphinx_rtd_theme">theme</a> provided by <a href="https://readthedocs.org">Read the Docs</a>. 

</footer>

        </div>
      </div>

    </section>

  </div>
  


  

    <script type="text/javascript">
        var DOCUMENTATION_OPTIONS = {
            URL_ROOT:'../',
            VERSION:'0.1',
            COLLAPSE_INDEX:false,
            FILE_SUFFIX:'.html',
            HAS_SOURCE:  true,
            SOURCELINK_SUFFIX: '.txt'
        };
    </script>
      <script type="text/javascript" src="../_static/jquery.js"></script>
      <script type="text/javascript" src="../_static/underscore.js"></script>
      <script type="text/javascript" src="../_static/doctools.js"></script>
      <script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.1/MathJax.js?config=TeX-AMS-MML_HTMLorMML"></script>

  

  
  
    <script type="text/javascript" src="../_static/js/theme.js"></script>
  

  
  
  <script type="text/javascript">
      jQuery(function () {
          SphinxRtdTheme.StickyNav.enable();
      });
  </script>
   

</body>
</html>